<?php
if(isset($_GET['kw'])) {
	$kw = daddslashes($_GET['kw']);
	$sql=" `content` LIKE '%{$kw}%'";
	$numrows=$DB->count("SELECT count(*) from authguao_chat WHERE{$sql}");
	$con='包含 '.$kw.' 的共有 <b>'.$numrows.'</b> 条聊天记录';
	$link='&kw='.$_GET['kw'];
}else{
	$sql=" 1";
	$numrows=$DB->count("SELECT count(*) from authguao_chat WHERE{$sql}");
	$con='授权平台共有 <b>'.$numrows.'</b> 条聊天记录';
}
?>
<div class="lite-chatbox" id="chat_con" style="height:400px;overflow:auto;">
<?php
$rs=$DB->query("select * from authguao_chat where{$sql} order by id asc");
while($res = $DB->fetch($rs))
{
	$userrow = $DB->get_row("select * from authguao_user where uid='" . $res['uid'] . "'");
	$sjxs=$res['date'];
	$chat_time=$res['time'];
	$chat_time2=$res['time2'];
	$datemz=explode(' ',$sjxs);
	$houzmc=explode(':',$datemz[1]);
	$sjian=intval($houzmc[0]);
	if ($sjian>0 && $sjian<=6) {
		$swu='凌晨';
	}else if ($sjian>6 && $sjian<=11) {
		$swu='上午';
	}else if ($sjian>11 && $sjian<=13) {
		$swu='中午';
	}else if ($sjian>13 && $sjian<=16) {
		$swu='下午';
	}else if ($sjian>16 && $sjian<=18) {
		$swu='傍晚';
	}else if ($sjian>18 && $sjian<=24) {
		$swu='晚上';
	}
	$time=date('Y-m-d').' 00:00:00';
	$mrrqi=date('Y-m-d',strtotime('-1 day')).' 00:00:00';
	$mrrqi2=date('Y-m-d',strtotime('-2 day')).' 00:00:00';
	$mrrqi3=date('Y-m-d',strtotime('-3 day')).' 00:00:00';
	$xxisj=$houzmc[0].':'.$houzmc[1];
	if ($sjxs>=$time) {
		$jtian=$swu.$xxisj;
	}else if ($sjxs>$mrrqi && $sjxs<$time) {
		$jtian='昨天'.$swu.$xxisj;
	}else if ($sjxs>$mrrqi2 && $sjxs<$mrrqi) {
		$jtian='2天前'.$swu.$xxisj;
	}else if ($sjxs>$mrrqi3 && $sjxs<$mrrqi2) {
		$jtian='3天前'.$swu.$xxisj;
	}else if ($sjxs<$mrrqi3) {
		$jtian=$datemz[0].$xxisj;
	}
	if ($islogin == 1) {
	$uid = 1;
	}else{
	$uid = $userrow['uid'];
	}
	if ($res['uid'] == 1) {
		$TxHtml = '<span class="htitle owner">平台站长</span>';
	} else if (!$userrow) {
		$TxHtml = '';
	} else {
		if ($userrow['power'] == 3) {
			$TxHtml = '<span class="htitle admin">全能管理员</span>';
		} else if ($userrow['power'] == 2) {
			$TxHtml = '<span class="htitle cg">超级管理员</span>';
		} else if ($userrow['power'] == 1) {
			$TxHtml = '<span class="htitle sqs">授权商</span>';
		} else if ($userrow['power'] == 0) {
			$TxHtml = '<span class="htitle">普通用户</span>';
		} else {
			$TxHtml = '';
		}
	}
	$timeHtml = '';
	if($chat_time - $chat_time2 > 120){
		$timeHtml = '<div class="tips"><span>'.$jtian.'</span></div>';
	}
	if ($res['uid'] != $uid) {
		$pd='<div class="cleft cmsg"><img class="headIcon radius" ondragstart="return false;"  oncontextmenu="return false;" onclick="chat_site('.$res['uid'].')" src="//q4.qlogo.cn/headimg_dl?dst_uin='.$res['qq'].'&spec=100" /><span class="name">'.$TxHtml.qqname($res['qq']).'</span><span class="content">'.ubb_parse($res['content']).'</span></div>';
	}else{
		$pd='<div class="cright cmsg"><img class="headIcon radius" ondragstart="return false;"  oncontextmenu="return false;" onclick="chat_site('.$res['uid'].')" src="//q4.qlogo.cn/headimg_dl?dst_uin='.$res['qq'].'&spec=100" /><span class="name">'.$TxHtml.qqname($res['qq']).'</span><span class="content">'.ubb_parse($res['content']).'</span></div>';
	}
	echo $timeHtml.$pd;
}
if(isset($_GET['kw'])) {
	if($numrows==0){
		echo '<li class="list-group-item"><center><font color="red">未搜索到相关的聊天记录</font></center></li>';
	}
}else{
	if($numrows==0){
		echo '<li class="list-group-item"><center><font color="red">无人在聊天公屏发言</font></center></li>';
	}
}
?>
</div>
<script>
$(function(){
	var d = $('#chat_con');
	if(d.length>0){
		d.scrollTop(d.prop("scrollHeight"));
		$("#chat_con").animate({scrollTop: 9999},1000);
	}
});
$("#blocktitle").html('<?php echo $con?>');
</script>